package com.store;

import java.util.ArrayList;
import java.util.List;

import com.jedi.BaseObj;
import com.tss.util.DbConn;
import com.tss.util.DbRs;

public class TechconengMgr extends BaseObj{
	
	public Techconeng get(String id) {
		clearErr();
		Techconeng techconeng = new Techconeng();
		
		DbConn conn = new DbConn();
		try {
			String sql = "";
			sql = "select t.* from techconeng t where t.conid=?,t.taskid = ?,engid=?";
			conn.prepare(sql);
			conn.setString(1,id);
			DbRs rs = conn.executeQuery();
			if (rs == null || rs.size() ==0) return null;
			techconeng.setConid(getInt(rs,0,"conid"));
			techconeng.setEngid(get(rs,0,"engid"));
			techconeng.setTaskid(getInt(rs,0,"taskid"));
			techconeng.setAssigntime(getDate(rs,0,"assigntime"));
			return techconeng;
		}
		catch(Exception ex) {
			ex.printStackTrace();
			setErr(ex.getMessage());
			return null;
		}
		finally {
			conn.close();
		}
	}
	/**
	 * 合同是否分配了工程师 incon_list.jsp
	 * @param id
	 * @return
	 */
	public boolean hasTechcon(int conid) {
		clearErr();
		
		
		DbConn conn = new DbConn();
		try {
			String sql = "";
			sql = "select t.* from techconeng t where t.conid=?";
			conn.prepare(sql);
			conn.setInt(1,conid);
			DbRs rs = conn.executeQuery();
			if (rs != null && rs.size() >0) {
				return true;
				}else	return false;
		}
		catch(Exception ex) {
			ex.printStackTrace();
			setErr(ex.getMessage());
			return false;
		}
		finally {
			conn.close();
		}
	}
	public List get(String otherSQL,String orderField) {
		clearErr();
		DbConn conn = new DbConn();
		DbRs rs = null;
		try {
			String sql = "";
			sql = "select * from techconeng where 1=1";
			if (otherSQL != null && !otherSQL.trim().equals("")) 
				sql += otherSQL;
			if (orderField != null && !orderField.trim().equals(""))
				sql += " order by " + orderField;
			conn.prepare(sql);
			rs = conn.executeQuery();
		}
		catch(Exception ex) {
			ex.printStackTrace();
			setErr(ex.getMessage());
			return null;
		}
		finally {
			conn.close();
		}
		if (rs != null && rs.size() >0) {
			List r = new ArrayList();
			for(int i=0;i<rs.size();i++) {
				Techconeng techconeng = new Techconeng();
				techconeng.setConid(getInt(rs,i,"conid"));
				techconeng.setEngid(get(rs,i,"engid"));
				techconeng.setTaskid(getInt(rs,i,"taskid"));
				techconeng.setAssigntime(getDate(rs,i,"assigntime"));
				r.add(techconeng);
			}
			return r;
		}
		return null;
	}
}
